package com.example.tests;

import org.testng.annotations.Test;

import com.example.fw.FolderHelper;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;



public class TestFolderCreation extends TestBase{

	@Test
	public void testFolderCreation() {
		String folder = FolderHelper.generateRandomFolderName();
		Folders oldFolders = app.getFolderHelper().getFolders(); 
		app.getFolderHelper().createFolder(folder);
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders, equalTo(oldFolders.withAdded(folder)));
	}
	
	@Test
	public void testVariousCreation() {
		String folder1 = FolderHelper.generateRandomFolderName();
		String folder2 = FolderHelper.generateRandomFolderName();
		
		Folders oldFolders = app.getFolderHelper().getFolders(); 
		assertThat(app.getFolderHelper().createFolder(folder1), is(nullValue()));
		Folders newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders, equalTo(oldFolders.withAdded(folder1)));
		
		oldFolders = app.getFolderHelper().getFolders(); 
		assertThat(app.getFolderHelper().createFolder(folder2), is(nullValue()));
		newFolders = app.getFolderHelper().getFolders();
		assertThat(newFolders, equalTo(oldFolders.withAdded(folder2)));
	}
	
	@Test
	public void testCreationTwoFoldersWithSameName() {
		String folder = FolderHelper.generateRandomFolderName();

		assertThat(app.getFolderHelper().createFolder(folder), is(nullValue()));
		assertThat(app.getFolderHelper().createFolder(folder), containsString("Duplicate"));
	}
}
